#!/usr/bin/ksh


data_do=$(date +'%d') 
if [[ $data_do -eq 24 ]]
then
    exit 0;  
else
    echo '------------do------------' >> /script/backup_lev1_init_out.txt
fi



date >> /script/backup_lev1_init_out.txt
echo 'start rman lev1_cumulative '>> /script/backup_lev1_init_out.txt
mkdir -p /backup/trff/arch

mkdir -p /backup/trff/cum_backup_0
mkdir -p /backup/trff/cum_backup_1
mkdir -p /backup/trff/cum_backup_2
mkdir -p /backup/trff/cum_backup_3
mkdir -p /backup/trff/cum_backup_4
mkdir -p /backup/trff/cum_backup_5
mkdir -p /backup/trff/cum_backup_6

x1oooo=$(date +"%y_%m_%d")
x2oooo=$(date +"%w")

sed   's/x1oooo/'$x1oooo'/g'  /script/lev1_tpl.rman  >/script/lev1_tpl.rman1
sed   's/x2oooo/'$x2oooo'/g'  /script/lev1_tpl.rman1  >/script/lev1_backup.rman
#rman  backup
export LANG=en_US
export NLS_LANG="simplified chinese_china".zhs16gbk
export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss' 
export ORACLE_BASE=/ora10g
export ORACLE_HOME=$ORACLE_BASE/db
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib:/usr/local/lib
export PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_SID=trff


rman target /  cmdfile=/script/lev1_backup.rman  log=/script/lev1_backup.rman.log  
    
#delete  backup
bl_day=3
del_day=0
this_w=$(date +"%w")
let del_day=7-$bl_day
    

while  [ 1 -eq 1 ] 
do
    let del_day=$del_day-1
    if [[ ($del_day -lt 0)|| ( $del_day -ge 6) ]]
    then
        break
    fi
    
    let del_num=$this_w+$del_day+1
    if [[ $del_num -ge 7 ]]
    then
       let del_num=$del_num-7
    fi
    
 
   rm -fr /backup/trff/cum_backup_${del_num}   
    
    
done
    






 rman target /  cmdfile=/script/crosscheck_delete.rman  log=/script/crosscheck_delete.rman.log  

date >> /script/backup_lev1_init_out.txt
echo 'end rman backup '>> /script/backup_lev1_init_out.txt



